package com.vvlive.caibao.smartcity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vvlive.caibao.smartcity.bean.ProcessDetails;
import com.vvlive.caibao.smartcity.bean.ProcessHeader;
import com.vvlive.caibao.smartcity.felm.SectionedBaseAdapter;

import java.util.List;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by zhj on 2015/12/14.
 * <p/>
 * +------------------------+
 * | 1     18:00 -- 18:30   |
 * |       XX:XXXX          |
 * |       XX:XXXX          |
 * +------------------------+
 * <p/>
 * +------------------------+
 * | 2     19:00 -- 19:30   |
 * |       XX:XXXX          |
 * |       XX:XXXX          |
 * +------------------------+
 * <p/>
 * 会议议程adapter
 */
public class ProcessAdapter extends SectionedBaseAdapter {

    private List<ProcessHeader> mHeaders;
    private List<List<ProcessDetails>> mDetails;
    private LayoutInflater mInflater;

    public ProcessAdapter(Context mContext, List<ProcessHeader> mHeaders, List<List<ProcessDetails>> mDetails) {
        this.mHeaders = mHeaders;
        this.mDetails = mDetails;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public Object getItem(int section, int position) {
        return mDetails.get(section).get(position);
    }

    @Override
    public long getItemId(int section, int position) {
        return position;
    }

    @Override
    public int getSectionCount() {
        return mHeaders.size();
    }

    @Override
    public int getCountForSection(int section) {
        return mDetails.get(section).size();
    }

    @Override
    public View getItemView(int section, int position, View convertView, ViewGroup parent) {
        ItemViewHolder itemViewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_process_details, null);
            itemViewHolder = new ItemViewHolder(convertView);
            convertView.setTag(itemViewHolder);
        } else {
            itemViewHolder = (ItemViewHolder) convertView.getTag();
        }
        ProcessDetails details = mDetails.get(section).get(position);
        itemViewHolder.project.setText("项目：" + details.getProject());
        itemViewHolder.reporter.setText("报告人：" + details.getReporter());
        return convertView;
    }

    static class ItemViewHolder {
        public TextView project;
        public TextView reporter;

        public ItemViewHolder(View itemView) {
            project = (TextView) itemView.findViewById(R.id.process_project);
            reporter = (TextView) itemView.findViewById(R.id.process_reporter);
        }
    }

    @Override
    public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
        HeaderViewHolder headerViewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_process_header, null);
            headerViewHolder = new HeaderViewHolder(convertView);
            convertView.setTag(headerViewHolder);
        } else {
            headerViewHolder = (HeaderViewHolder) convertView.getTag();
        }
        ProcessHeader headerData = mHeaders.get(section);
        headerViewHolder.number.setText(headerData.getNumber() + "");
        headerViewHolder.time.setText(headerData.getTime());
        return convertView;
    }

    static class HeaderViewHolder {
        public TextView number;
        public TextView time;

        public HeaderViewHolder(View itemView) {
            number = (TextView) itemView.findViewById(R.id.process_number);
            time = (TextView) itemView.findViewById(R.id.process_time);
        }
    }
}
